function [a,P] =GoToBall(P,S,mode)

if(isempty(S) || size(S{1},2)~=2),a='turn 45';
else if(~isempty(S) && size(S{1},2)==2)
        B=S{1};
        
        P_X=P{1}(1);
        P_Y=P{1}(2);
        P_theta=P{1}(3);
        P_pace = P{5};
        
        B_VX=B{2}(1);
        B_VY=B{2}(2);
        %angle=0;
        
        if(mode=='p')    %partial observability
            B_R=B{1}(1);
            B_alpha=B{1}(2);
            
            
            angle=P_theta+B_alpha;
            
            B_X=P_X+B_R*cos(angle/180*pi);
            B_Y=P_Y+B_R*sin(angle/180*pi);
            
            
        else
            B_X=B{1}(1);
            B_Y=B{1}(2);
        end
        
        angle3=atan2(B_Y+3*B_VY-P_Y,B_X+3*B_VX-P_X)/pi*180;    %compute the angle to the ball after 3 time steps in degrees
        
        if(angle3<0)
            angle3=angle3+360;    %correct the angle3
        end
        angle3=angle3-P_theta;      %the angle between the player and the ball after 3 steps
        if(angle3<0)
            angle3=angle3+360;    %correct the angle3
        end
        
        angle3=round(angle3/45)*45;   %discretize angle3 into the nearest 45 degree
        
        if(angle3<=45 || angle3>=360-45)
            %a='dash 10';
            a = sprintf('dash %d', P_pace);
            
        else
            r=rand(1);
            if(r>0.7),
                %a = 'dash 10';
                a = sprintf('dash %d', P_pace);
            else
                if(angle3<180)
                    a=sprintf('turn %d',angle3);
                else
                    a=sprintf('turn %d',angle3-360);
                end
            end
        end
        
    end
    
end

end